<template>
  <li @mousemove="isEnter = true"
      @mouseleave="isEnter = false"
      :class="isEnter ? 'active' : ''"
  >
    <label>
      <!--  $event.target 进行类型断言  HTMLInputElement-->
      <!--  数据操控试图变化-->
      <input
         :checked="todo.done"
          @change="changeChecked(todo.id,($event.target as HTMLInputElement).checked)"
          type="checkbox"
      />
      <span>{{ todo.thing }}</span>
    </label>
    <button class="btn btn-danger" @click="deleteTodo(todo.id)">删除</button>
  </li>
</template>

<script lang="ts">
import {defineComponent,ref} from 'vue';
export default defineComponent({
  name: "Item"
})
</script>

<script lang="ts" setup>
import {todoType} from '@/types/todoList'

//接收props传参定义类型（事件函数一般都没有返回值，返回值类型写void）
interface propsType{
  todo:todoType,
  changeChecked:(id:string,done:boolean)=>void,
  deleteTodo:(id:string)=>void,
}
// defineProps返回一个Proxy对象，包含所有props  ，页面中使用要   Proxy对象.数据
// Proxy(Object) {todo: Proxy(Object), changeChecked: ƒ, deleteTodo: ƒ}
defineProps<propsType>()

// 定义变量，来区分移入移出情况
let isEnter = ref<boolean>(false)
</script>

<style scoped>
li {
  list-style: none;
  height: 36px;
  line-height: 36px;
  padding: 0 5px;
  border-bottom: 1px solid #ddd;
}

li label {
  float: left;
  cursor: pointer;
}

li label li input {
  vertical-align: middle;
  margin-right: 6px;
  position: relative;
  top: -1px;
}

li button {
  float: right;
  display: none;
}

li:before {
  content: initial;
}

li:last-child {
  border-bottom: none;
}

li.active {
  background-color: #ccc;
}

li.active button {
  display: block;
}
</style>
